 ;(function (mod){
	var addCookie=function(objName, objValue, objHours){
		    var str = objName + "=" + escape(objValue);
		    str += ";domain=kf.qq.com";
		    if (objHours > 0) {
		        var date = new Date();
		        var ms = objHours * 3600 * 1000;
		        date.setTime(date.getTime() + ms);
		        str += ";expires=" + date.toGMTString();
		    }
		    document.cookie = str;
		};

	var getCookie=	function(name){
		    var search = name + "=",cookies = document.cookie.split(" ");
		     for (var i = 0,l = cookies.length; i < l; i++) {
		     	var pair = cookies[i].split(";")[0];
		     	if (pair.indexOf(search) == 0) {
		        	var offset = search.length;
		            	var end = pair.length;
		            	return pair.substring(offset, end);
		        	}
			}
		    return "";
		};
		
	var announce_speed='slow';
	var announce_obj="";
	var _host="http://kf.qq.com";
	var emergency_an=[];
    var auto_hide_announce_time=10000;// 自动隐藏紧急公告的时长
    var init_announce; 
	/**
	 * 隐藏公告列表
	 */
	var hide_announce_list=function (){
		$("#announce_id").removeClass("notice_on");
		$("#announce_static_page").stop(false, true).hide(announce_speed);
	}
	/**
	 * 公告的显示与隐藏
	 */
	var toggle_announce=function () {
		var noticeTab=$(".kf_mod_top_bar .notice"),
		slideNotice=$(".kf_mod_top_bar .slide_notice");
		
		$(".kf_mod_top_bar .log_info").on("mouseover",function(event){
			if($(event.target).attr("class")=="notice"){
				noticeTab.addClass("notice_on");
				slideNotice.finish().css({"display":"block","opacity":"0","top":"180px"}).animate({opacity:1,top:"28px"},250,function(){});
			}else if($(event.target).attr("class")=="slide_notice"){
				slideNotice.show();
			}else if(($(event.target).attr("class")=="line")||($(event.target).attr("class")=="weibo")||($(event.target).attr("class")=="log_out")){
				noticeTab.removeClass("notice_on");
				slideNotice.finish().animate({opacity:0,top:"180px"},400,function(){$(this).hide();});	
			}else{
			}
		});
	
		$(noticeTab).on("mouseleave",function(event){
			if(event.pageY<24){
				noticeTab.removeClass("notice_on");
				slideNotice.finish().animate({opacity:0,top:"180px"},400,function(){$(this).hide();});
			}
		});
		
		$(slideNotice).on("mouseleave",function(){
			noticeTab.removeClass("notice_on");
			slideNotice.finish().animate({opacity:0,top:"180px"},400,function(){$(this).hide();});	
		});
	};
	
	var auto_hide_announce=function (){// 自动隐藏紧急公告
		 init_announce=setTimeout(hide_announce,auto_hide_announce_time);
	};
	var hide_announce=function (){// 隐藏紧急公告
		$("#em_more").attr("class","op fold_down");
		$("#em_content,#em_pg_nav").hide();	
	};
	/**
	 * 生成公告下拉列表
	 */
	var get_announce=function (){
		$("#announce_id").html('<i class="icon icon_notice_orange" id="announce_icon"></i>公告');
		var announce_list="";
		for(var i=0;i<announce_obj.length;i++){
			var an_status="";// 是否有图标，HOT,NEW,或者没有
			var obj=announce_obj[i];
			
			if(obj.level==2){//
				if(obj.scope==1){// 范围是全站
					emergency_an.push(obj);
				}else {

					var prodcut_area_name=$("#pro_second_code").val();
					  if(obj.scope.length>1){
						  var tmp=obj.scope;
						  for(var m=0;m<tmp.length;m++){
							  if(prodcut_area_name===tmp[m]){// 当前产品专区
								  emergency_an.push(obj);
							  }
						  }
					  }else{
						  if(prodcut_area_name===obj.scope[0]){// 当前产品专区
							  emergency_an.push(obj);
						  }
					  }
				}
				obj.title="<span class='font_red'>"+obj.title+"</span>";
			}
			
		   if(i===0){
				an_status="<i class='icon icon_new'></i>";
			}else if(i==1){
				//an_status="<i class='icon icon_hot'></i>";
			}

			var blank="target='_blank'";// 新窗口打开标志
			var _links=obj.href;
			if(_links.indexOf("http")==-1 && _links.indexOf("https")==-1){
				_links=_host+"/"+_links;
			}
			var tmp_date=obj.pub_time.split("/");
			obj.pub_time=tmp_date[1]+"."+tmp_date[2];
			announce_list+='<li id="announce_'+obj.id+'" >	<em class="tlt" ><span class="dot">·</span><a  class="a_tag" href="'+_links+'"  '+blank+' title="'+obj.title+'"> '+obj.title +'</a>'+an_status+'</em><span  class="pub_time">'+obj.pub_time +'</span></li>';
		}
		if(emergency_an.length>0){
			var em_first=emergency_an[0];
			$("#em_title").html(em_first.title);
			
			//$("#em_content_to").html(em_first.to);
			$("#em_content_body").html(em_first.content);
			//$("#em_content_sign").html(em_first.sign);
			
			if(emergency_an.length>1){
				var str="<div class='pg' style='display:none' id='em_pg_nav'>";
				for(var j=0,k=emergency_an.length;j<k && j<3 ;j++){// 最多三条
					str+="<a href='javascript:KF.com.single_announce("+j+")' class='"+(j===0?"on":"")+"' title='第"+(j+1)+"页'>"+(j+1)+"</a>";
				}
	            str+="</div>";
	            $("#em_pg").append(str);
			}
			$("#em_container").show();
		}
		$("#announce_static_page").append(announce_list);
		
		var is_init_announce=getCookie("init_emergency_announce");
		if(is_init_announce!=1){
			$("#em_more").attr("class","op fold_up");
			$("#em_content,#em_pg_nav").show();
			addCookie("init_emergency_announce",1);	
			auto_hide_announce();
		}
};


	$("#announce_static_page li").on("click",function(){// 点击公告列表
		var a_id=$(this).attr("id").substr(9);// "announce_"的长度
		var obj="";
		for(var i in announce_obj){
			if(announce_obj[i].id==a_id){
				obj=announce_obj[i];
				break;
			}
		}
		if(obj===""){
			return false;
		}
		hide_announce_list();
	});
mod.toggle_single_announce=function(){
	if($("#em_more").attr("class")=="op fold_down"){
		$("#em_content,#em_pg_nav").show();
		$("#em_more").attr("class","op fold_up");
	}else{
		hide_announce();
	}
};
mod.single_announce=function(current_index){
	$("#em_pg_nav a").each(function(j){
		var $this=$(this);
		if($this.text()==current_index+1){
			$this.attr("class","on");
		}else{
			$this.attr("class","");
		}
	});
	var cur_an=emergency_an[current_index];
	$("#em_title").html(cur_an.title);
	$("#em_content_to").html(cur_an.to);
	$("#em_content_body").html(cur_an.content);
	$("#em_content_sign").html(cur_an.sign);
};
mod.announce = function () {
	$.ajax({
		url: "http://kf.qq.com/announces.html?nocache=" + Math.random() * 1000000,
		dataType: "text",
		timeout: 3000,
		success:function(msg){
		try{
				announce_obj=eval('('+msg+')');
				get_announce();
				toggle_announce() ;			
			}catch(err){
				window.console&&console.log(err);
			}
		},
		error:function(rep){window.console &&console.log(rep);}
	});
};

　　　　return mod;
　　})( window.KF.com || {});